﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CNRSccp.Claims.DAO;
using CNRSccp.Claims.Helper;


namespace CNRSccp.Claims
{
    class SQLConfig
    {

        /// <summary>
        /// Get CLAIM Table configuration for specific SPSite tenant (Using propertybag value for database name)
        /// </summary>
        public static List<ClaimDbConfigEntity> GetClaimsDatabaseConfig(string DatabaseConnectionString, string ClaimsTableName)
        {
            List<ClaimDbConfigEntity> LstClaimDbConfigEntity = null;
            try
            {
                BaseDAO daoList = new BaseDAO(DatabaseConnectionString, ClaimsTableName);
                DAOParameter parameter = new DAOParameter() { Columns = "Server,DatabaseName,Login,Password" };
                LstClaimDbConfigEntity = daoList.GetClaimItems(parameter);
            }
            catch (Exception)
            {
                //TODO log
            }

            return LstClaimDbConfigEntity;
        }

        /// <summary>
        /// Get LDAP Table configuration for specific SPSite tenant (Using propertybag value for database name)
        /// </summary>
        public static List<LdapDbConfigEntity> GetLdapDatabaseConfig(string DatabaseConnectionString, string LdapTableName)
        {
            List<LdapDbConfigEntity> LstLdapDbConfigEntity = null;
            try
            {
                BaseDAO daoList = new BaseDAO(DatabaseConnectionString, LdapTableName);
                DAOParameter parameter = new DAOParameter() { Columns = "DirectoryEntry,ServerBind,UserAccount,Password,Query,Attribut,SSL" };
                LstLdapDbConfigEntity = daoList.GetLdapItems(parameter);
            }
            catch (Exception)
            {
                //TODO log
            }

            return LstLdapDbConfigEntity;
        }


        /// <summary>
        /// Get CLAIMSELEMENT Table configuration for specific SPSite tenant (Using propertybag value for database name)
        /// </summary>
        public static List<ClaimsElement> GetClaimsElementDatabaseConfig(string DatabaseConnectionString, string ClaimsElementTableName)
        {
            List<ClaimsElement> LstClaimElementEntity = null;
            try
            {
                BaseDAO daoList = new BaseDAO(DatabaseConnectionString, ClaimsElementTableName);
                DAOParameter parameter = new DAOParameter() { Columns = "Title,Type,ClaimKey,ReferenceID,DB,FormatDisplay,Format,Hidden" };
                LstClaimElementEntity = daoList.GetClaimsElementItems(parameter);
            }
            catch (Exception)
            {
                //TODO log
            }

            return LstClaimElementEntity;
        }


    }
}
